<template>
  <div>
    <el-input :disabled="disabled" v-model="fnumber" @input="edit_fnumber" :suffix-icon="loading"></el-input>
  </div>

</template>

<script>
import NumRuleManagerApi from "@/api/numRule/NumRuleManagerApi";
import {numberRole} from "@/const/NumbeRole";

export default {
  name: "tieNumberRole",
  props: {
    classKey: String,
  },
  data() {
    return {
      disabled: true,
      fnumber: '',
      loading: "el-icon-loading"
    }
  },
  created() {
    this.initNumber()
  },
  methods: {
    async initNumber() {
      const api = new NumRuleManagerApi();
      const resp = await api.getNumber2({entityResultClass: numberRole[this.classKey]}).catch(() => this.disabled = false)
      const result = resp.data
      //取消局部loading
      this.loading = ''

      if (result.number === '') {
        this.disabled = false;
        return
      }

      if (result.isAddView) {
        this.fnumber = result.number
        this.$emit('input', result.number)
        //用于js获取fnumber
        this.$emit('Js-get—number', result.number)
      }

      if (result.edit) {
        this.disabled = false;
      }

    },

    //实时将修改的值发送给父组件
    edit_fnumber(fnumber) {
      this.$emit('input', fnumber)
      this.$emit('Js-get—number', fnumber)
    }
  }

}
</script>

<style scoped>

</style>
